const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('-') 
}

const formatTimeHour = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
 
  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute].map(formatNumber).join(':')
}
const getInspectStatusName = status=> {
  var statusName = ""
  switch (status) {
    case 1:
      statusName = "审核"
      break;
    case 2:
      statusName = "修改检查单"
      break;
    case 3:
      statusName = "待检查"
      break;
    case 4:
      statusName = "发布整改单"
      break;
    case 5:
      statusName = "隐患评估"
      break;
    case 6:
      statusName = "审核"
      break;
    case 7:
      statusName = "整改"
      break;
    case 8:
      statusName = "整改审核"
      break;
    case 9:
      statusName = "验收"
      break;
    case 10:
      statusName = "督办整改"
      break;
    case 11:
      statusName = "督办整改审核"
      break;
    case 12:
      statusName = "督办验收"
      break;
    case 13:
      statusName = "督办验收审核"
      break;
    case 14:
      statusName = "整改验收审核"
      break;
    case 15:
      statusName = "结束"
      break;
    default:
      statusName = "未知状态"
  }
  return statusName
}


const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

const decode = input => {
    let resultStr=decodeURIComponent(atob(input).split('').map(function(c) {
        return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
    }).join(''));
    return JSON.parse(resultStr)
}

module.exports = {
  formatTime: formatTime,
  getInspectStatusName: getInspectStatusName,
    formatTimeHour:formatTimeHour,
    decode:decode
}